package com.vehicle.admin.web.common;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Author:yjck
 * Email:1367676880@qq.com
 * Date:2017/12/26
 * Time:20:20
 * Describe:全局异常处理 处理Shiro注解跳转
 */
@ControllerAdvice
public class GlobalExceptionHandler {
    @ExceptionHandler(value = org.apache.shiro.authz.UnauthorizedException.class)
    public ModelAndView defaultErrorHandler(HttpServletRequest request, HttpServletResponse response,Exception e) throws IOException {
        response.sendRedirect("/common/500");
        ModelAndView mav=new ModelAndView();
        mav.addObject("exception",e);
        mav.addObject("url",request.getRequestURL());
        mav.setViewName("/common/unauthorized");

        return mav;
    }
}
